package ru.volgogradetzzz.tween.easing {

	public class Bounce {
		public static function easeOut(time:uint, before:Number, change:Number, duration:uint):Number {
			var ratio:Number = time / duration;			
			if (ratio < (1 / 2.75)) {
				return change * (7.5625 * ratio * ratio) + before;
			} else if (ratio < (2 / 2.75)) {
				return change * (7.5625 * (ratio -= (1.5 / 2.75)) * ratio + .75) + before;
			} else if (ratio < (2.5 / 2.75)) {
				return change * (7.5625 * (ratio -= (2.25 / 2.75)) * ratio + .9375) + before;
			} else {
				return change * (7.5625 * (ratio -= (2.625 / 2.75)) * ratio + .984375) + before;
			}
		}
		
		public static function easeIn(time:uint, before:Number, change:Number, duration:uint):Number {
			return change - easeOut(duration - time, 0, change, duration) + before;
		}
		
		public static function easeInOut(time:uint, before:Number, change:Number, duration:uint):Number {
			if (time < duration / 2) {
				return easeIn(time * 2, 0, change, duration) * .5 + before;
			}
			
			return easeOut(time * 2 - duration, 0, change, duration) * .5 + change * .5 + before;
		}		
	}
}
